import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:ls_work/a_mine/models/week_record_entity.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/styles.dart';

class MeWeekListCell extends StatelessWidget {
  final List<WeekInfo>? infoList;
  MeWeekListCell({Key? key, this.infoList});
  // static const List<String> _weeks = const ["一", "二", "三", "四", "五", "六", "日"];
  // static const List<String> _days = const [
  //   "11-1",
  //   "11-2",
  //   "11-3",
  //   "11-4",
  //   "11-5",
  //   "11-6",
  //   "11-7"
  // ];
  // static const List<String> _states = const ["白", "白", "夜", "夜", "白", "白", "夜"];

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(15),
      width: ScreenUtil.getScreenW(context),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            '本周班表',
            style: TextStyles.textBoldDark16,
          ),
          SizedBox(height: 20),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: _buildWeeks(),
          )
        ],
      ),
    );
  }

  Widget _item(String date, String day, String statue, bool isSelected) {
    return Container(
      padding: EdgeInsets.all(5),
      decoration: BoxDecoration(
          color: isSelected ? Colours.app_main : Colors.white,
          borderRadius: BorderRadius.circular(5)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          Text(date,
              style: TextStyle(fontSize: 12, color: getTextColor(isSelected))),
          Text(day,
              style: TextStyle(fontSize: 12, color: getTextColor(isSelected))),
          SizedBox(
            height: 5,
          ),
          Text(statue,
              style: TextStyle(
                  fontSize: 16,
                  color: isSelected ? Colors.white : Colours.text_dark))
        ],
      ),
    );
  }

  List<Widget> _buildWeeks() {
    List<Widget> widgets = [];
    String date =
        DateUtil.formatDate(DateTime.now(), format: DateFormats.y_mo_d);
    print(date);
    for (int i = 0; i < (infoList??[]).length; i++) {
      String schedulingTypeSymbol = infoList![i].schedulingTypeSymbol??"";
      widgets.add(Center(
        child: _item(infoList![i].dateSymbol??"", infoList![i].week??"",
            schedulingTypeSymbol, (date == infoList![i].date)),
      ));
    }
    return widgets;
  }

  getTextColor(bool isSelected) {
    return isSelected ? Colors.white : Colours.text_gray;
  }
}
